<script setup>
  import {computed, ref} from 'vue'
  import { useRouter } from 'vue-router'
  import EditUserInfo from "@/views/mine/components/EditUserInfo.vue";
  import EnterShop from "@/views/mine/components/EnterShop.vue";
  import {message} from "ant-design-vue";
  import {useUserStore} from "@/stores/index.js";
  const mem = computed(() => useUserStore().mem)
  const editUserInfoRef = ref()
  const enterShopRef = ref()
  const router = useRouter()
  const visible = ref(false)
  const nav = (name) => {
    router.push({ name })
  }
  const logout = () => {
    message.warn('退出登录')
  }
  const popover = (name) => {
    visible.value = false
    if (name === 'edit') {
      editUserInfoRef.value.open()
    } else if (name === 'logout') {
      // logout()
    } else {
      nav(name)
    }
  }
</script>

<template>
  <div class="user-info">
    <div class="avatar-name">
      <img :src="mem.avatar" class="avatar" alt="">
      <div class="user-name">
        <div class="name"> {{ mem.name }} </div>
        <div class="level"> 等级：{{ mem.member_level }} </div>
      </div>
      <div class="setting">
        <a-popover v-model:open="visible" placement="bottomRight">
          <template #content>
            <div>
              <a-button type="text" @click="popover('edit')"> 修改资料 </a-button>
            </div>
            <div>
              <a-button type="text" @click="popover('about')"> 关于我们 </a-button>
            </div>
            <div>
              <a-button type="text" @click="popover('help')"> 帮助中心 </a-button>
            </div>
            <div>
              <a-button block type="text" @click="popover('logout')"> 退出登录 </a-button>
            </div>
          </template>
          <i class="fa-solid fa-gear"></i>
        </a-popover>
      </div>
    </div>
    <div class="tag-td">
      <div class="user-tag"> 用户、销售 </div>
      <div class="gs-name" @click="enterShopRef.open()"> 公司名称/店铺申请 </div>
    </div>
    <div class="user-desc"> 描述 </div>
    <EditUserInfo ref="editUserInfoRef" />
    <EnterShop ref="enterShopRef" />
  </div>
</template>

<style scoped lang="scss">
  .user-info {
    display: flex;
    flex-direction: column;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #f8f8f8;
    gap: 10px;
    .avatar-name {
      gap: 15px;
      display: flex;
      align-items: center;
      position: relative;
      .avatar {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        object-fit: contain;
        border: 5px solid var(--primary);
      }
      .name {
        width: 220px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .setting {
        position: absolute;
        top: 0;
        right: 0;
        cursor: pointer;
        &:hover {
          color: var(--primary);
        }
      }
    }
    .tag-td {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .user-desc {
      color: #999;
    }
  }
  @media (max-width: 750px) {
    .avatar-name {
      text-align: center;
      flex-direction: column;
      .avatar {
        margin-top: 40px;
      }
    }
  }
</style>